\chapter{CLUBs documentation}
\label{appenix:documentation}
\section{Identifiers}
The following object types can be expressed as literals:
	\begin{itemize}
		\item Boolean - \textit{true} or \textit{false}.
		\item String - surrounded by quotation marks, ex. \textit{"foo"}.
		\item Integer - ex. \textit{42}.
	\end{itemize}
	
\section{Reserved words}
A list of reserved words can be found in appendix \ref{chapter::Tokens}.

\section{Comments}
To write a comment in CLUBs simply add \textit{//} before the desired comment.
\section{Program Structure}

To make a game in CLUBs it must contain the token \textit{game} followed by opening and closing curly brackets, this declares a game. A game must contain the token \textit{start} followed by opening and closing curly brackets. All the code inside \textit{start} is the first thing it will execute when running a game in CLUBs.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
game
{
	start
	{
		//This is the smallest game possible
	}
}
\end{lstlisting}

The most common thing to have inside \textit{start} is the round you want to execute. For this you need to declare a \textit{round}, and then use the build-in function \textit{UseRound} to declare which round you want to use.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
game
{
	start
	{
		UseRound(aRound);
	}
	round aRound
	{
		//This is a round.
	}
}
\end{lstlisting}

The next thing you need is a player. One of the properties you must set in a player is the \textit{MainPiece}. The \textit{MainPiece} is the piece you want your player to have as default. You can change this during a game if necessary. The piece needs some kind of icon, this is set through a string that takes the path to a picture file, you want to use, like the example below.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
game
{
	...
	player myPlayer
	{
		MainPiece = myPiece;
	}
	piece myPiece
	{
		Icon = "myIcon.png";
	}
}
\end{lstlisting}

Inside a \textit{round} you can declare what should happen in the game. We recommend using turn as seen below, because this will give a better overview for multiplayer games. To use a turn you must declare it by using the \textit{turn} token, followed by the name of the turn. In the round you must also tell it which turn you want to use with the build in function \textit{DoTurn}, which takes a turn and a player as input.


\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
game
{
	...
	round aRound
	{
		DoTurn(aTurn, myPlayer);
	}
	turn aTurn
	{
		//What you want to do during a turn.
	}
}
\end{lstlisting} 

The next thing you are going to need in a game is a board. The simplest board you can create is a standard board. The only thing you need to decide is the size. This is done my using the build in function \textit{MakeRect} to make your board any size you want.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
game
{
	...
	board myBoard
	{
		MakeRect(5,5);
	}
	
}
\end{lstlisting}

The next thing to do is to define what should happen during the turn. To place a piece using the action \textit{PlacePiece} we need two things, the piece we want to place, and the cell we want to place it in. Now to access a cell using the mouse you need to use \textit{SelectCell}. \textit{SelectCell} takes two arguments, a property on the cell and a Boolean. In the example below we use the property "full", which is automatically set each turn, and holds information about whether or not a cell is full, in this case it must be false e.g. not full.

\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
game
{
	...
	turn aTurn
	{
		piece currentPiece = CurrentPlayer->MainPiece;
		cell currentCell = SelectCell("Full", false);
		PlacePiece(currentPiece, currentCell);
	}
	
}
\end{lstlisting} 


That were the basics of CLUBs you now know how to implement a basic board game, with no goals, just one player setting pieces where he wants. Of cause it is possible to do more advanced games in CLUBs which will be described in the following sections.


\section{Variables}
\label{Variables:Main}
\subsubsection{Boolean}
\label{Variables:Boolean}
A Boolean can have two different values, \textit{true} or \textit{false}.

\subsubsection{String}
A string expression consists of a quotation mark any number of characters and an end quotation mark.\\ 
Example: "This is a string"
\subsubsection{Int}
An interger expression can be any integral number between.
\section{Data Types}
\label{DataTypes:Main}
In this section we cover the different data types and the predefined properties the hold.
\subsubsection{Board}
Used to declare a board object or class. Contains the property CellType used if you want to use a custom cell.
\subsubsection{Cell}
Used to declare a cell object or class. Contains MaxPieces, an integer which is used to limited the amount of pieces that can be placed on that type of cell.
\subsubsection{Piece}
Used to declare a piece object or class. Contains Icon, a path in form of a string, used to declare the type of icon for that piece.
\subsubsection{Player}
Used to declare a player object or class. Contains MainPiece, the piece that player uses as default.
\subsubsection{Round}
Used to declare a Round object or class.
\subsubsection{Turn}
Used to declare a Turn object or class.

\section{Statements}
There are four types of statements in CLUBs. Three of them are covert in this section, but Control Structure is covered later on in section \ref{ControlStructures:Main}

\subsection{Declaration Statements}
An declaration statement is declared in the following form "Type Identifier;". Type can be any data type from CLUBs\footnote{They can be found in section \ref{DataTypes:Main}} and the identifier consist of one letter followed by any number of letters or digits.
A few examples of declarations.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
// declaring a Boolean
bool mybool;
// declaring an integer
int my1Int;
\end{lstlisting} 

\subsection{Assign Statements}
An assign statement is defined in the following form "variable = expression;". The variable can be any variable found in section \ref{Variables:Main}, and expression must be a matching expression from section \ref{Expressions:Main}.
A few examples of statements.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
// setting a Boolean, that been declared earlier.
mybool = true;
// setting an integer, that been declared earlier.
myInt = 42;
\end{lstlisting} 

You can also combine declaration and assignment.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
// first declaring the assigning.
bool mybool = true;
// first declaring the assigning.
int myInt = 42;
\end{lstlisting} 


\section{Expressions}
\label{Expressions:Main}
An expression in a CLUBs is a combination of values, variables, operators, and actions calls.


\subsection{Call Statements}
Call statements are used to call actions. Actions can be found in section \ref{Functions:Main}. A function may take a number of arguments that must be matched when calling. Example:
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
//Calling function
myFunction();
//Calling function that takes an argument
myFunction(myAgrument);
//Calling function that takes two argument
myFunction(myFirstAgrument,mySecoundAgrument);
\end{lstlisting} 

\subsection{Operator Expressions}
There are also six operators in CLUBs:\\
\textit{+},\textit{-},\textit{*},\textit{/},\textit{is} and \textit{not}.
These can be used as part of an expression. Example:\\
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
//simple plus expression
1+1
//a not expression
not true
\end{lstlisting} 
Note that while \textit{+} adds to numbers, \textit{is} is used to compare if two numbers, strings or Boolean values are the same. And \textit{not} is used to invert a Boolean.


\section{Control Structures}
\label{ControlStructures:Main}
There are four types of control structures CLUBs.
\subsubsection{If}
An if statement, is used by writing the token \textit{if} followed by parentheses, between these parentheses there must be at Boolean expression\footnote{Recall from section \ref{Variables:Boolean}}. After this there follows curly brackets, and between them, the code you want to execute.

Example:
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
bool mybool = true;
if (myBool is true)
{
	//do stuff.
}
\end{lstlisting} 
\subsubsection{Check}
A check statement, is used by writing the token \textit{check} followed by parentheses, between these parentheses there must by an expression. After this follow some curly brackets, and between them, the cases you want. If you look at the example below. You see two cases, one for each possible value of a Boolean.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
bool mybool = true;
check(myBool)
	case: true
	{
		//do stuff.
	}
	case: false
	{
		//do some other stuff.
	}
}
\end{lstlisting} 

\subsubsection{While}
A while loop is like an if, but it is using the token \textit{while}. There is one key difference between it and while, if runs only ones, but a while loop continues to run until the expression becomes false. 
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
bool mybool = true;
while(myBool is true)
{
	//doing stuff until myBool is false.
}
\end{lstlisting}
\subsubsection{For}
Now a for statement that is a bit more tricky. It takes two statements and an expression. First the token \textit{for} followed by parentheses. Between them you first need to declare an integer, then you need an expression, followed by some increment for the integer. In the example below, $i$ starts at one then as long as it is below a hundred it will add one to $i$.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
for(int i = 0; i < 100; i+1)
{
	//doing stuff a number of times.
}
\end{lstlisting}

\section{Actions}
\label{Functions:Main}
%action
When declaring an action in CLUBs you need to use the action token \textit{action} followed by the name of the action, also called the identifier, and curly brackets. Between the curly brackets you write the code you want executed when you run the action.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
action DoSomething
{
	//Something goes here.
}
\end{lstlisting}

You can also make an action give a type as output by using the \textit{gives} token. At the end of the action used \textit{give(identifier)} to give it back.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
action DoSomething gives bool
{
	bool myBool = true;
	give(myBool);
}
\end{lstlisting}

You can also make an action take one or more type as input by using the \textit{takes} token.
myBool can then be accessed and used inside the action.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
action DoSomething takes bool myBool
{
	myBool = false;
}
\end{lstlisting}

\section{System Methods / System API}
In this section we are going to give an overview of the different build in function available.

\subsection{MakeRect}
Used inside a board to define it's size and shape. It takes two integers as argument, one for the height and one for the weight of the rectangle.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
board example
{
	MakeRect(3,3)
}
\end{lstlisting}
\subsection{UseRound}
Used inside a class to define which round it should be used. It takes a round an argument.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
UseRound(aRound);
\end{lstlisting}

\subsection{DoTurn}
Used inside a class to define which turn should be used. It takes a turn and a player as arguments.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
DoTurn(aTurn, aPlayer);
\end{lstlisting}

\subsection{PlacePiece}
Used inside a class to place a piece in a cell. It takes a piece and an cell as arguments.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
PlacePiece(currentPiece, currentCell);
\end{lstlisting}

\subsection{SelectCell}
Used inside a class to use the mouse input to select a cell. It takes two arguments, a property on the type of cell you want to select, and a Boolean to check on that property. It gives the selected cell if the condition is met.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
SelectCell("empty", true);
\end{lstlisting}

\subsection{GetCellAt}
Used inside a class to get a spefic cell in the current active board. It takes two arguments one for the x coordinate and one for the y coordinate.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
GetCellAt(x,y);
\end{lstlisting}


\section{Extended Example}
\label{appenix:documentation:ExtendedExample}
If we take the entire example from the earlier, it looks like this:
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]	
game
{
	board myBoard
	{
		MakeRect(5,5);
	}
	start
	{
		UseRound(aRound);
	}
	round aRound
	{
		DoTurn(aTurn, myPlayer);
	}
	player myPlayer
	{
		MainPiece = myPiece;
	}
	piece myPiece
	{
		Icon = "myIcon.png";
	}
	turn aTurn
	{
		piece currentPiece = CurrentPlayer->MainPiece;
		cell currentCell = SelectCell("Full", false);
		PlacePiece(currentPiece, currentCell);
	}
	
}
\end{lstlisting} 

Now a board can contain the properties \textit{CellType} which is the kind of cell you want to use, otherwise it will just use a default cell. Now if you have declare a costum cell you can set the property \textit{MaxPieces} which declares how many pieces there can be in a cell, by default this is $-1$ which is unlimited.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]		
game
{
	...
	board myBoard
	{
		CellType = myCell;
		MakeRect(5,5);
	}
	cell myCell
	{
		MaxPieces = 1;
	}
}
\end{lstlisting} 
The next thing we want is to switch between two players. 
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]		
game
{
	...
	player myPlayerTwo
	{
		MainPiece = myPieceTwo;
	}
	piece myPieceTwo
	{
		Icon = "myIconTwo.png";
	}
	round MainRound
	{
		DoTurn(aTurn, myPlayer);
		DoTurn(aTurn, myPlayerTwo);
	}
}
\end{lstlisting} 

Now let's add a winning condition to the game.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]		
game
{
	...
	turn aTurn
	{
		piece currentPiece = CurrentPlayer->MainPiece;
		cell currentCell = SelectCell("Full", false);
		PlacePiece(currentPiece, currentCell);
		WinningCondition();
	}
	action WinningCondition
	{
		
	}
}
\end{lstlisting} 
Now the action WinningCondition is executed at the end of each turn. Now we just need to write the winning condition.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]		
game
{
	...
	action WinningCondition gives bool takes board b, piece p, int width, int height
	{
		
	}
}
\end{lstlisting} 

Here we define that the action WinningCondition gives a bool and takes three arguments. The pieces we want to check, and the width and height of the board.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={ using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of TTT},]
game
{
	...
	action WinningCondition gives bool takes piece p, int width, int height
	{
		//We start at x at 0.
		int x = 0;
		int y;
		cell c1;
		cell c2;
		//as long as x is less then the width.
		while (not (x is width)) 
		{
			y = 0;
			//as long as y is less then the height.
			while (not (y is (height)))
			{
				//We get the two cells. 
				c1 = GetCellAt(x,y);
				c2 = GetCellAt(x+1,y);
				//Check if they belong to the same player.
				if (GetFirstPiece(c1) is p)
				{
					if (GetFirstPiece(c2) is p)
					{
						// and gives true.
						give(true);
					}
				}
				//else we cont y one up.
				y = y + 1;
			}
			//else we cont x one up.
			x = x + 1;
		}
		//If the two loop terminate, the player was not won.
		give(false);
	}
}
\end{lstlisting} 
